本文共 538 字,大约阅读时间需要 1 分钟。
import smtplibfrom email.mime.text import MIMEText# 邮件配置smtp_server = 'smtp.163.com'smtp_port = 25from_email = 'email@163.com'auth_code = 'your_password'to_email = 'fuck0@qq.com'# SMTP客户端初始化smtp = smtplib.SMTP(smtp_server, smtp_port)smtp.login(from_email, auth_code)# 创建邮件对象msg = MIMEText('这是一个测试邮件')msg['Subject'] = '【测试邮件】'msg['From'] = from_emailmsg['To'] = to_email# 发送邮件smtp.sendmail(from_email, to_email, msg.as_string())smtp.close() 注:以上代码用于通过163邮箱发送测试邮件,确保配置信息(如邮箱地址和授权码)已正确填写。如果需要发送到多个收件人,可将to_email改为多个地址的列表形式。
转载地址:http://bzwu.baihongyu.com/